﻿using FitnessClubManager.BLL;
using FitnessClubManager.GUI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace QuanLyHocPhi.GUI.DuLieu
{
    public partial class FormQuanLyTu : FormBase
    {
        public FormQuanLyTu()
        {
            InitializeComponent();
            gridTu.ReadOnly = true;
            gridTu.AllowUserToAddRows = false;
            gridTu.AllowUserToDeleteRows = false;
            gridTu.AutoGenerateColumns = false;
            NapDanhSachTu();
        }
        void NapDanhSachTu()
        {
            var ls = BizSanPham.DanhSachTuForGrid();
            bsTu.DataSource = ls;
            gridTu.DataSource = bsTu;
        }

        private void btnThemTu_Click(object sender, EventArgs e)
        {
            FormTaoMoiTu form = new FormTaoMoiTu();
            form.ShowDialog();
            NapDanhSachTu();
        }

        private void btnXoaTu_Click(object sender, EventArgs e)
        {
            if (bsTu.Current != null)
            {
                var item = bsTu.Current as SanPhamForGrid;
                if (!BizSanPham.Delete(item.MaSanPham))
                    DialogUtils.ShowError("Không thể xóa tủ này");
                else
                    NapDanhSachTu();
            }
        }
    }
}
